package com.coderside.fragment.concurrent.volatil;

import java.util.Random;

/**
 * 								指定一个随机数55
 *  启动两个线程 一个线程不断地打印日志 ----------------------------------------------
 * 一个线程不断生成随机数与指定的随机数比较 直到生成的随机数与指定随机数相等 停止第一个线程
 * 
 * @author 197370
 * 
 */
public class StateSymbol {

	public static void main(String[] args) {
		new StateSymbol().test();
	}

	private void test() {
		new Thread(new TestRun1()).start();
		new Thread(new TestRun2()).start();
	}

	private volatile boolean shutDownRequested;

	private final int randomNum = 55;

	class TestRun1 implements Runnable {

		public void run() {
			while (!shutDownRequested) {
				System.out.println(Math.random());
			}

		}
	}

	public void shutdown() {
		shutDownRequested = true;
	}

	class TestRun2 implements Runnable {
		public void run() {
			Random ran = new Random();
			int ranNum = 0;
			while (ranNum != randomNum) {
				ranNum = ran.nextInt(100);
			}
			System.out.println(ranNum);
			shutdown();
		}
	}
}
